/***********************************************************************************************************************
/*
/*    tray.cpp
/*
/**********************************************************************************************************************/

#include "stdafx.h"

#include <shellapi.h>


//----------------------------------------------------------------------------------------------------------------------
//  ON TRAY ICON
//----------------------------------------------------------------------------------------------------------------------
void wm_tray_icon ( WPARAM wParam, LPARAM lParam )
{
	wParam;

	switch ( lParam )
	{
#if 0
	case WM_RBUTTONUP:
		{
			POINT mouse;
			GetCursorPos(&mouse);
			show_pop_up_menu();
			PostMessage(g_hwnd, WM_NULL, 0, 0);
		}
		break;
#endif

	case WM_LBUTTONUP:
		{
			if ( g_Settings.bExpanded )
			{
				ShowWindow ( g_hwnd, SW_RESTORE );
				ShowWindow ( g_hwndMini, SW_HIDE );
			}

			else
			{
				ShowWindow ( g_hwnd, SW_HIDE );
				ShowWindow ( g_hwndMini, SW_RESTORE );
			}
		}

		break;

	case WM_LBUTTONDBLCLK:
		break;
	}
}


//----------------------------------------------------------------------------------------------------------------------
//   ADD TASK BAR ICON
//----------------------------------------------------------------------------------------------------------------------
void add_tray_icon ( HICON hIcon )
{
	NOTIFYICONDATA d;
	memset ( &d, 0, sizeof(d) );
	d.cbSize = sizeof ( d );
	d.uID = 0;
	d.hIcon = hIcon;
	d.hWnd = g_hwnd;
	d.uFlags = NIF_ICON | NIF_MESSAGE ; // | NIF_TIP;
	d.uCallbackMessage = uWM_TRAY_ICON;
	wcscpy_s ( d.szTip, sizeof(d.szTip), g_awAppTitle );
	Shell_NotifyIcon ( NIM_ADD, & d );
}


//----------------------------------------------------------------------------------------------------------------------
//  REMOVE TASK BAR ICON
//----------------------------------------------------------------------------------------------------------------------
void remove_tray_icon ()
{
	NOTIFYICONDATA d;
	memset ( &d, 0, sizeof(d) );
	d.cbSize = sizeof ( d );
	d.hWnd = g_hwnd;
	d.uID = 0;
	d.uFlags = NIF_ICON | NIF_TIP;
	Shell_NotifyIcon ( NIM_DELETE, & d );
}